// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) 
// Source File Name:   OrderStatusScrPanel.java

package com.boci.clientapp.orderstatus;

import com.boci.clientapp.main.ApplicationService;
import com.boci.clientapp.main.ClientAppLoader;
import com.boci.clientapp.orderstatus.action.OrderStatusAction;
import com.boci.clientapp.orderstatus.ui.control.HKMarketPanel;
import com.boci.clientapp.orderstatus.ui.control.HKOptionPanel;
import com.boci.clientapp.orderstatus.ui.control.USMarketPanel;
import com.boci.clientapp.orderstatus.ui.control.USOptionPanel;
import com.boci.common.ui.AbstractPanel;
import com.boci.common.util.*;
import com.boci.common.vo.ResponseVO;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.*;
import javax.swing.border.LineBorder;

public class OrderStatusScrPanel extends AbstractPanel
    implements ActionListener
{

    public OrderStatusScrPanel(Locale pLocale, String pModuleName, String pScreenName)
    {
        super(pLocale, pModuleName, pScreenName);
        lastSelectedIndex = -1;
        initGUI(pLocale);
        setText(pLocale);
    }

    public int getSelection()
    {
        if(lastSelectedIndex == -1)
            return 0;
        else
            return lastSelectedIndex;
    }

    public void setText(Locale pLocale)
    {
        super.setText(pLocale);
        setFont(pLocale);
        MessagesConfigurator msgConf = ClientAppLoader.getMessagesConfigurator();
        lblQtyRemark.setText(msgConf.getUIMessages("ORDER_STATUS.QTY_REMARK1", pLocale));
        lblQtyRemark2.setText(msgConf.getUIMessages("ORDER_STATUS.QTY_REMARK2", pLocale));
        hkMarketPanel.setText(pLocale);
        usMarketPanel.setText(pLocale);
        hkOptionPanel.setText(pLocale);
        usOptionPanel.setText(pLocale);
        btnGo.setText(msgConf.getUIMessages("ORDER_STATUS.GO", pLocale));
        cmbOrderStatus.setModel(new DefaultComboBoxModel(new String[] {
            msgConf.getUIMessages("ORDER_STATUS.ALL", pLocale), msgConf.getUIMessages("ORDER_STATUS.HKMARKET", pLocale), msgConf.getUIMessages("ORDER_STATUS.USMARKET", pLocale), msgConf.getUIMessages("ORDER_STATUS.HKOPTION", pLocale), msgConf.getUIMessages("ORDER_STATUS.USOPTION", pLocale)
        }));
        if(lastSelectedIndex != -1)
            cmbOrderStatus.setSelectedIndex(lastSelectedIndex);
    }

    private void setFont(Locale pLocale)
    {
        btnGo.setFont(ClientAppLoader.getPlainButtonFont(pLocale));
        cmbOrderStatus.setFont(ClientAppLoader.getSmallPlainTextFont(pLocale));
        lblQtyRemark.setFont(ClientAppLoader.getDisclaimerFont(pLocale));
        lblQtyRemark2.setFont(ClientAppLoader.getDisclaimerFont(pLocale));
    }

    private void initGUI(Locale pLocale)
    {
        setPreferredSize(null);
        initHeaderPanel();
        initOrderStatusPanel(pLocale);
        setLayout(new BorderLayout());
        add(headerPanel, "North");
        add(orderStatusPanel, "Center");
    }

    private void initOrderStatusPanel(Locale pLocale)
    {
        orderStatusPanel = new JPanel();
        hkMarketPanel = new HKMarketPanel(pLocale);
        usMarketPanel = new USMarketPanel(pLocale);
        hkOptionPanel = new HKOptionPanel(pLocale);
        usOptionPanel = new USOptionPanel(pLocale);
        JPanel gapPanel = new JPanel();
        gapPanel.setOpaque(false);
        gapPanel.setPreferredSize(new Dimension(0, 39));
        gapPanel.setLayout(null);
        lblQtyRemark = new JLabel();
        lblQtyRemark.setBounds(5, 5, 720, 20);
        lblQtyRemark2 = new JLabel();
        lblQtyRemark2.setBounds(5, 19, 720, 20);
        gapPanel.add(lblQtyRemark);
        gapPanel.add(lblQtyRemark2);
        orderStatusPanel.setOpaque(false);
        orderStatusPanel.setLayout(new BoxLayout(orderStatusPanel, 1));
        orderStatusPanel.add(hkMarketPanel);
        orderStatusPanel.add(usMarketPanel);
        orderStatusPanel.add(hkOptionPanel);
        orderStatusPanel.add(usOptionPanel);
        orderStatusPanel.add(gapPanel);
    }

    private void initHeaderPanel()
    {
        headerPanel = new JPanel();
        cmbOrderStatus = new JComboBox();
        btnGo = new JButton();
        headerPanel.setLayout(null);
        headerPanel.setOpaque(false);
        headerPanel.setPreferredSize(new Dimension(0, 25));
        cmbOrderStatus.setBounds(2, 2, 150, 20);
        cmbOrderStatus.setBorder(new LineBorder(new Color(128, 128, 192), 1, false));
        headerPanel.add(cmbOrderStatus);
        btnGo.setMargin(new Insets(0, 0, 0, 0));
        btnGo.setBounds(155, 2, 22, 20);
        btnGo.setActionCommand("GO");
        btnGo.addActionListener(this);
        headerPanel.add(btnGo);
    }

    public void actionPerformed(ActionEvent e)
    {
        PerformanceLogger.startAppTimer();
        lastSelectedIndex = cmbOrderStatus.getSelectedIndex();
        String strActionType = e.getActionCommand();
        OrderStatusAction orderStatusAction = new OrderStatusAction();
        orderStatusAction.doProcess(getInputValue(strActionType), strActionType);
        PerformanceLogger.stopAppTimer();
        PerformanceLogger.doLog((new StringBuilder()).append(getScreenName()).append(".").append(strActionType).toString());
    }

    public void showOrderStatusTable(int pCmbIndex)
    {
        lastSelectedIndex = pCmbIndex;
        cmbOrderStatus.setSelectedIndex(pCmbIndex);
        if(pCmbIndex == 0)
        {
            hkMarketPanel.setVisible(true);
            usMarketPanel.setVisible(true);
            hkOptionPanel.setVisible(true);
            usOptionPanel.setVisible(true);
            hkMarketPanel.setVisibleLblBtn(true);
            usMarketPanel.setVisibleLblBtn(false);
            hkOptionPanel.setVisibleLblBtn(false);
            usOptionPanel.setVisibleLblBtn(false);
        } else
        if(pCmbIndex == 1)
        {
            hkMarketPanel.setVisible(true);
            usMarketPanel.setVisible(false);
            hkOptionPanel.setVisible(false);
            usOptionPanel.setVisible(false);
            hkMarketPanel.setVisibleLblBtn(true);
            usMarketPanel.setVisibleLblBtn(false);
            hkOptionPanel.setVisibleLblBtn(false);
            usOptionPanel.setVisibleLblBtn(false);
        } else
        if(pCmbIndex == 2)
        {
            hkMarketPanel.setVisible(false);
            usMarketPanel.setVisible(true);
            hkOptionPanel.setVisible(false);
            usOptionPanel.setVisible(false);
            hkMarketPanel.setVisibleLblBtn(false);
            usMarketPanel.setVisibleLblBtn(true);
            hkOptionPanel.setVisibleLblBtn(false);
            usOptionPanel.setVisibleLblBtn(false);
        } else
        if(pCmbIndex == 3)
        {
            hkMarketPanel.setVisible(false);
            usMarketPanel.setVisible(false);
            hkOptionPanel.setVisible(true);
            usOptionPanel.setVisible(false);
            hkMarketPanel.setVisibleLblBtn(false);
            usMarketPanel.setVisibleLblBtn(false);
            hkOptionPanel.setVisibleLblBtn(true);
            usOptionPanel.setVisibleLblBtn(false);
        } else
        if(pCmbIndex == 4)
        {
            hkMarketPanel.setVisible(false);
            usMarketPanel.setVisible(false);
            hkOptionPanel.setVisible(false);
            usOptionPanel.setVisible(true);
            hkMarketPanel.setVisibleLblBtn(false);
            usMarketPanel.setVisibleLblBtn(false);
            hkOptionPanel.setVisibleLblBtn(false);
            usOptionPanel.setVisibleLblBtn(true);
        }
    }

    public void resetSelection()
    {
        if(cmbOrderStatus != null)
        {
            lastSelectedIndex = 0;
            cmbOrderStatus.setSelectedIndex(0);
        }
    }

    public void refresh()
    {
        OrderStatusAction orderStatusAction = new OrderStatusAction();
        orderStatusAction.doProcess(getInputValue("GO"), "GO");
        setDefFocus();
    }

    public void refresh(ResponseVO pResponseVO)
    {
        if(pResponseVO == null)
        {
            lastUpdateDateTime = null;
            updateAllLastUpdateTime();
        }
        hkMarketPanel.refresh(pResponseVO);
        usMarketPanel.refresh(pResponseVO);
        hkOptionPanel.refresh(pResponseVO);
        usOptionPanel.refresh(pResponseVO);
        setDefFocus();
    }

    public HashMap getInputValue(String pActionType)
    {
        HashMap inpMap = new HashMap();
        String strAcctNo = ApplicationService.getInstance().getAccountNo();
        inpMap.put("select2", strAcctNo);
        inpMap.put("submit_go", "Go");
        return inpMap;
    }

    public boolean validate(String pActionType)
    {
        return true;
    }

    public void setLastUpdateDateTime(Date pLastUpdateDateTime)
    {
        lastUpdateDateTime = pLastUpdateDateTime;
    }

    public String getOrderCancelLastUpdateDateTimeStr()
    {
        if(lastUpdateDateTime == null)
            return "";
        else
            return StringUtil.formatOrderCancelLastUpdatedDateTime(lastUpdateDateTime);
    }

    public String getOrderChangeLastUpdateDateTimeStr()
    {
        return getOrderCancelLastUpdateDateTimeStr();
    }

    public String getOrderStatusLastUpdateDateTimeStr()
    {
        if(lastUpdateDateTime == null)
            return "";
        else
            return StringUtil.formatLastUpdatedDateTime(lastUpdateDateTime);
    }

    public void updateAllLastUpdateTime()
    {
        if(hkMarketPanel != null)
            hkMarketPanel.updateLastUpdateTime();
        if(usMarketPanel != null)
            usMarketPanel.updateLastUpdateTime();
        if(hkOptionPanel != null)
            hkOptionPanel.updateLastUpdateTime();
        if(usOptionPanel != null)
            usOptionPanel.updateLastUpdateTime();
    }

    public void setDefFocus()
    {
        SwingUtilities.invokeLater(new Runnable() {

            public void run()
            {
                cmbOrderStatus.requestFocus();
                cmbOrderStatus.setSelectedIndex(getSelection());
            }
        }
);
    }

    private JPanel headerPanel;
    private JPanel orderStatusPanel;
    private JComboBox cmbOrderStatus;
    private JButton btnGo;
    private HKMarketPanel hkMarketPanel;
    private USMarketPanel usMarketPanel;
    private HKOptionPanel hkOptionPanel;
    private USOptionPanel usOptionPanel;
    private int lastSelectedIndex;
    private Date lastUpdateDateTime;
    private JLabel lblQtyRemark;
    private JLabel lblQtyRemark2;

}
